
import {go_to, request, showMsg} from '../../../utils/util.js';
import { JsDetail,JsDel } from '../../../config/api.js';
import { wxParse } from '../../../utils/wxParse/wxParse.js';

const app = getApp();
var random = Math.random();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    title: '记事详情',
    detail: {},
    navH:0,
    hidden: false
  },
  fetchDetail: function (id) {
    let _this = this;
    request(JsDetail+'?id='+id, 'GET').then(function (res) {
      console.log(res);
      if (res.s == 1) {
        var content = res.d.info.content;
        wxParse('content', 'html', content, _this, 25);
        _this.setData({
          detail:res.d.info,
          hidden: true
        });        
      }else{
        _this.setData({
          hidden: false
        })
      }
    })       
  },

  article_edit: function(e){
    let id = e.currentTarget.dataset.id;
    go_to('reLaunch','pages/index/add/add','id='+id);
  },

  article_del: function(e){
    let id = e.currentTarget.dataset.id;
    let _this = this;
    request(JsDel+'?id='+id, 'GET').then(function (res) {
      if (res.s == 1) {
        showMsg('删除成功',1);
        go_to('switchTab','pages/index/index/index');
      }else{
        showMsg('删除失败',2);
      }
    }) 
  },
  

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that= this;

    let navH = app.globalData.navHeight;
    /*顶部导航高度*/
    that.setData({
      hidden: false,
      navH: navH
    });
    this.fetchDetail(options.id);
  }

})